<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
	#div1 {width: 100px; height: 100px; background: red; position: absolute;}
	
</style>
<script>
window.onload = function()
{
		var oDiv = document.getElementById('div1');
	
		var disX =0 ;
		var disY = 0;
	
		oDiv.onmousedown= function(ev)
		{
				//clientX clientY 鼠标坐标
				var oEvent = ev||event;
				disX = oEvent.clientX- oDiv.offsetLeft ;
				disY = oEvent.clientY -oDiv.offsetTop ;
			
				oDiv.onmousemove= function(ev)
				{
						var oEvent = ev||event;
						var left = oEvent.clientX - disX;
						var top = oEvent.clientY - disY;
						
						if(left<0)
						{
								left = 0;
						}

						if(top<0)
						{
								top = 0;
						}
					
						oDiv.style.left = left + 'px';
						oDiv.style.top = top + 'px';
						
				};
				
				oDiv.onmouseup = function()
				{
						oDiv.onmousemove =null;
						oDiv.onmouseup=null;
						oDiv.releaseCapture();
				};
			
			return false;   //已经解决了 FF chrome IE9及以上的问题
			
		};
};
</script>
</head>

<body>
<div>dasaad</div>
<div>89jkjkj</div>
<div>llmmmm</div>
	<div id="div1">dsadsada</div>

</body>
</html>
